import requests
from flask import Flask, render_template, request
import tool
from Logger import logger
import datetime



app = Flask(__name__)

#1.使用类传参 & 使用字典传参
@app.route('/')
def hello_world():
    return render_template('index.html')


@app.route('/memberinfo')
def memberinfo():
    return render_template('memberinfo.html')


#根据手机号查询会员信息
@app.route('/submit', methods=['POST'])
def submit():
    phoneno = request.form['phoneno']
    url = "http://test-debug.gqshintra.com/customer/h/com.guoquan.customer.client.MemberInfoClient/queryMemberBaseInfo"
    headers = {
        "Content-Type": "application/x-www-form-urlencoded",
        "Accept": "application/json"
    }
    data = {
        "model": '{"phone":"'+phoneno+'"}'
    }
    logger.info("----根据手机号查询会员信息------"+str(data))
    response = requests.post(url, headers=headers, data=data)
    print(response.json())
    allstr = response.json()
    print(allstr['data']['userId'])
    return f'查询的手机号为{phoneno}，返回的用户信息为{response.text}！'


if __name__ == '__main__':
    app.run('0.0.0.0', port=5001, debug=True)
